package com.fancy.controller;

import com.fancy.pojo.User;
import com.fancy.pojo.UserListenNumber;
import com.fancy.service.ListenNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

@RestController
@RequestMapping("/rank")
public class UserListenNumberController {
    @Autowired
    private ListenNumberService listenNumberService;

    @RequestMapping("/addNumber")
    public String listenNumberAdd(@RequestBody UserListenNumber userListenNumber){
        return listenNumberService.ListenNumberAdd(userListenNumber) ? "听歌数量加1" : "听歌数量增加失败";
    }

    @RequestMapping("/getRank")
    public Set<Object> getListenNumber(@RequestParam("userId") String userId){
        //System.out.println(userId);
        //System.out.println(listenNumberService.getListenNumber(userId));
        return listenNumberService.getListenNumber(Integer.parseInt(userId));
    }

    @RequestMapping("/readDate")
    public ArrayList<UserListenNumber> readDate(@RequestParam("userId") String userId){
        //System.out.println(listenNumberService.getUserByUserId(userId));
        return listenNumberService.getUserByUserId(Integer.parseInt(userId));
    }

    @RequestMapping("/getUserInfo")
    public User getUserInfo(@RequestParam("userId") String userId){
        //System.out.println(listenNumberService.readDate(userId));
        return listenNumberService.readDate(Integer.parseInt(userId));
    }

    @RequestMapping("/getListenNumberByUserId")
    public boolean getListenNumberByUserId(@RequestParam("userId") String userId){
        return listenNumberService.getListenNumberByUserId(Integer.parseInt(userId));
    }
}
